package com.vankimgps.listvehicles;

import java.util.ArrayList;

import com.vankimgps.activity.R;
import com.vankimgps.database.DatabaseHelper;
import com.vankimgps.models.ResponseVehicleStatus;
import com.vankimgps.models.ResponseVehicles;
import com.vankimgps.models.VehicleStatus;
import com.vankimgps.models.Vehicles;
import com.vankimgps.services.ServiceListener;
import com.vankimgps.services.Services;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

public class ListVehiclesActivity extends Activity implements
ServiceListener{
	ArrayList<VehicleStatus> _listVehicle;

	private ListVehiclesAdapter listVehiclesAdapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_vehicles_layout);
		
	    DatabaseHelper db = new DatabaseHelper(this);
	    String token = db.getToken();
	    String userID = db.getUserID();
	    
		Services service = new Services(this);
		Log.i("VANKIM","VAN KIM Token + UserID: " + token + "   " + userID);
		service.getVehicleStatus(token, userID);
	}
	
	public void onCompleted(Services service, Object result) {
		ResponseVehicleStatus response = (ResponseVehicleStatus)result;
		_listVehicle = new ArrayList<VehicleStatus>();
		_listVehicle = (ArrayList<VehicleStatus>)response.getList();
		listVehiclesAdapter = new ListVehiclesAdapter(this,
				R.layout.cell_vehicle_layout, _listVehicle);

		Log.i("VANKIM","VANKIM : onCompleted1");
		ListView listView = (ListView)findViewById(R.id.listVehicle);
		Log.i("VANKIM","VANKIM : onCompleted2");

		listView.setAdapter(listVehiclesAdapter);
	}
}
